<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function pagination($obj){
	if (!$obj) {
		return '';
	}

	$params = request()->param();
	return '<div class="imooc-app">'.$obj->appends($params)->render().'</div>';
}


/**
 *获取栏目名称
 */
function getCatName($catId){
	if (!$catId) {
		return '';
	}

	$cats = config('cat.lists');
	return !empty($catId)?$cats[$catId]:'';
}

function isYesNo($str){
	return $str?'<span style="color:red">是</span>':'<span>否</span>';
}

/**
 * [status 状态]
 * @param  [type] $id     [description]
 * @param  [type] $status [description]
 * @return [type]         [description]
 */
function status($id, $status) {
    $controller = request()->controller();

    $sta = $status == 1 ? 0 : 1;
    $url = url($controller.'/status', ['id' => $id, 'status' => $sta]);

    if($status == 1) {
        $str = "<a href='javascript:;' title='修改状态' status_url='".$url."' onclick='app_status(this)'><span class='label label-success radius'>正常</span></a>";
    }elseif($status == 0) {
        $str = "<a href='javascript:;' title='修改状态' status_url='".$url."' onclick='app_status(this)'><span class='label label-danger radius'>待审</span></a>";
    }

    return $str;
}

/**
 * [show 通用化api接口数据输出]
 * @param  [type] $status   [业务状态吗]
 * @param  [type] $message  [信息提示]
 * @param  [type] $data     [数据]
 * @param  [type] $httpcode [http状态码]
 * @return [type]           [array]
 */
function show($status,$message,$data=[],$httpcode=200){
        $data =  [
            'status'=>$status,
            'message'=>$message,
            'data'=>$data,
        ];
        return json($data,$httpcode);
}
